﻿using B.S.BaseData.Api.Write.Applicantion.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BataBase.Domain.Entitys;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;

namespace B.S.BaseData.Api.Write.Controllers
{
    /// <summary>
    /// 商品操作  -API  -写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class GoodsController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        public GoodsController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Upload(IFormFile file)
        {
            var path = Directory.GetCurrentDirectory() + "/wwwroot/Files/" + file.FileName;
            using (FileStream fs = new FileStream(path, FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            return Ok("http://localhost:5216/Files/" + file.FileName);
        }
        /// <summary>
        /// 商品新增
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodsAdd(GoodsInfoAddCommand request)
        {
            return await _mediator.Send(request);
        }
        /// <summary>
        /// 商品删除
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpDelete]
        public async Task<APIResult<int>> GoodsDelete([FromQuery]GoodsInfoDeleteCommand request)
        {
            return await _mediator.Send(request);
        }
        /// <summary>
        /// 商品批量删除
        /// </summary>
        /// <param name="command">对象</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodsbatchDelete(GoodsInfobatchDeleteCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 商品修改
        /// </summary>
        /// <param name="command">实体</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodsUpdate(GoodsInfoUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 产品检查图片新增
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodsproductsImgAdd(GoodsproductsImgAddCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 产品检查图片删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<APIResult<int>> GoodsproGoodscultivationAddductsImgDelete([FromQuery]GoodsproductsImgDeleteCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 养殖信息新增
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodscultivationAdd(GoodscultivationAddCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 养殖信息修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodscultivationUpdate(GoodscultivationUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 保健信息添加
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodshealthAdd(GoodshealthCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 保健信息删除
        /// </summary>
        /// <param name="command">保健id</param>
        /// <returns>返回任务</returns>
        [HttpDelete]
        public async Task<APIResult<int>> GoodshealDelete([FromQuery]GoodsHealDeleteCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 保健信息修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodshealthUpdate(GoodshealthUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 养殖企业信息新增
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodscultivationCompanyAdd(GoodscultivationCompanyAddCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 养殖企业信息修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodscultivationCompanyUpdate(GoodscultivationCompanyUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 屠宰信息新增
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodsslaughterAdd(GoodsslaughterAddCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 屠宰信息修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> HaGoodsslaughterUpdateCommandndle(GoodsslaughterUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 屠宰企业新增
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodsslaughterInfoCompanyAdd(GoodsslaughterInfoCompanyAddCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 屠宰企业修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodsslaughterInfoCompanyUpdate(GoodsslaughterInfoCompanyUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 深加工新增
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodschargeInfoAdd(GoodschargeInfoAddCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 原料新增
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodsvendorInfoAdd(GoodsvendorInfoAddCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 辅料新增
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodsvendorAccessories(GoodsvendorAccessoriesCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 添加剂新增
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodsvendoradditiveAdd(GoodsvendoradditiveAddCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 包材新增
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodsvendPackagingmaterialsAdd(GoodsvendPackagingmaterialsAddCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 深加工公司新增
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> GoodsProcessingInfoAdd(GoodsProcessingInfoAddCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 深加工小组修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodschargeInfoUpdate(GoodschargeInfoUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 原料修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodsvendorInfoUpdate(GoodsvendorInfoUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 辅料修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodsvendorAccessoriesUpdate(GoodsvendorAccessoriesUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 添加剂修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodsvendoradditiveUpdate(GoodsvendoradditiveUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 包材修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodsvendPackagingmaterialsUpdate(GoodsvendPackagingmaterialsUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 深加工公司修改
        /// </summary>
        /// <param name="command">实体类</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> GoodsProcessingInfoUpdate(GoodsProcessingInfoUpdateCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
